/**
 * kl yy-ds @2021
 */
package com.cxps.cloud.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.Map;

/**
 * TODO(类描述)
 *
 * @author YouCai.Liu
 * @since 2021/11/23
 * ...
 */
@Slf4j
public class JsonUtil {

    private static final ObjectMapper om;

    static {
        om = new ObjectMapper();
    }

    /**
     * Json 字符串转 map
     *
     * @param jsonStr
     * @return
     */
    public static Map<String, Object> jsonToMap(String jsonStr) {
        return jsonToObj(jsonStr, Map.class);
    }

    private static <T> T jsonToObj(String jsonStr, Class<T> cls) {
        try {
            return om.readValue(jsonStr, cls);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        return null;
    }

}
